<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;

class AvatarController extends Controller
{
    /**
     * 获取用户头像URL
     *
     * @param Request $request
     * @return JsonResponse
     */
    public function getAvatar(Request $request): JsonResponse
    {
        // 验证用户是否已认证
        $user = Auth::guard('sanctum')->user();
        if (!$user) {
            return response()->json([
                'message' => '用户未认证',
            ], 401);
        }

        $avatarUrl = $user->avatar ? asset('storage/' . $user->avatar) : null;
        
        return response()->json([
            'data' => [
                'avatar_url' => $avatarUrl,
                'avatar_path' => $user->avatar,
            ],
            'message' => '获取头像成功',
        ], 200);
    }
}
